package main.string;

import com.alibaba.fastjson.JSONObject;
import main.string.utill.CertificateTemplateDTO;
import main.string.utill.JsonUtil;
import main.string.utill.ReplyDTO;
import main.string.utill.ReplyDescDTO;
import org.junit.Test;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @create 2017-03-22 20:57
 **/
public class ObjectToJson2 {
	@Test
	public void test() throws Exception {
		JSONObject jsonObject =new JSONObject();

		jsonObject.put("type",1);
		jsonObject.put("key_words","关键字");
		jsonObject.put("response","回复");
		jsonObject.put("reply_desc","图文回复");

		List<ReplyDescDTO> replyDescDTOS = new ArrayList<ReplyDescDTO>();

		ReplyDescDTO replyDescDTO = new ReplyDescDTO();
		replyDescDTO.setBrief("简介");
		replyDescDTO.setUri("www.baidu.com/1.jpg");
		replyDescDTO.setTitle("图文标题");
		replyDescDTO.setCoverPicture("www.bidu.com/1.txt");
		replyDescDTOS.add(replyDescDTO);

		ReplyDescDTO replyDescDTO2 = new ReplyDescDTO();
		replyDescDTO2.setBrief("简介");
		replyDescDTO2.setUri("www.baidu.com/1.jpg");
		replyDescDTO2.setTitle("图文标题");
		replyDescDTO2.setCoverPicture("www.bidu.com/1.txt");
		replyDescDTOS.add(replyDescDTO2);

		ReplyDescDTO replyDescDTO3 = new ReplyDescDTO();
		replyDescDTO3.setBrief("简介");
		replyDescDTO3.setUri("www.baidu.com/1.jpg");
		replyDescDTO3.setTitle("图文标题");
		replyDescDTO3.setCoverPicture("www.bidu.com/1.txt");
		replyDescDTOS.add(replyDescDTO3);

		jsonObject.put("reply_desc_DTOS",replyDescDTOS);

		System.out.println(jsonObject.toString());


		String content = "{\"keywords\":\"关键字\",\"reply_desc\":\"图文回复\",\"reply_desc_d_t_o_s\":[{\"brief\":\"简介\",\"cover_picture\":\"www.bidu.com/1.txt\",\"title\":\"图文标题\",\"uri\":\"www.baidu.com/1.jpg\"},{\"brief\":\"简介\",\"cover_picture\":\"www.bidu.com/1.txt\",\"title\":\"图文标题\",\"uri\":\"www.baidu.com/1.jpg\"},{\"brief\":\"简介\",\"cover_picture\":\"www.bidu.com/1.txt\",\"title\":\"图文标题\",\"uri\":\"www.baidu.com/1.jpg\"}],\"response\":\"回复\",\"type\":1}";

		Type type = new com.google.gson.reflect.TypeToken<ReplyDTO>() {
		}.getType();
		ReplyDTO replyDTO = JsonUtil.parseJson(content,type);
		System.out.println(
				"agentLimitRuleVO...:{}" + JsonUtil.toJson(replyDTO));

	}

}
